using Game.Component.Character;
using Game.Const;
using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class CharacterItem : BaseItem
	{
		public const float LIE_LEFT_ANGLE = 90f;

		public const float SIT_Y_GAP = 0.852f;

		public const float CHARACTER_HEIGHT = 2.9f;

		public float characterHeight = 2.9f;

		public float headStartY;

		public float hairStartY;

		public Head head;

		public Body body;

		public Hand leftHand;

		public Hand rightHand;

		public Leg leftLeg;

		public Leg rightLeg;

		public Face face;

		public Hair frontHair;

		public Hair backHair;

		public Color32 headColor;

		public CharacterAnimator animator;

		private bool isIll;

		private float waitCure;

		private Vector2 lastMovePos = new Vector2(-100f, -100f);

		private float hairAnimTimer;

		private bool isPlayBlowHairAnim;

		private float tempHairScale;

		private float tempHairAngle;

		private bool isPlayShakeAnim;

		private float tempShakeX;

		private float tempShakeY;

		protected float blinkTime;

		private int topsIndex;

		protected bool isLock;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			headColor = archiveData.color;
			InitCharacter();
			IsIll(data.intParam1 == 1);
		}

		protected virtual void InitCharacter()
		{
			body = new Body(model.Find("Body"), -10, -13, 14, -1, -11);
			head = new Head(model.Find("Body/Head"), -12);
			face = new Face(model.Find("Body/Head/Face"));
			frontHair = new Hair(model.Find("Body/Head/FrontHair"), Hair.Dir.Front);
			backHair = new Hair(model.Find("Body/Head/BackHair"), Hair.Dir.Back);
			leftHand = new Hand(model.Find("Body/LeftHand"), Hand.Dir.Left);
			rightHand = new Hand(model.Find("Body/RightHand"), Hand.Dir.Right);
			leftLeg = new Leg(model.Find("Body/LeftLeg"), Leg.Dir.Left);
			rightLeg = new Leg(model.Find("Body/RightLeg"), Leg.Dir.Right);
			headStartY = head.transform.localPosition.y;
			hairStartY = headStartY + frontHair.transform.localPosition.y;
			InitComponentTrigger(model.Find("Body/LeftHand/UpperArm/LowerArm").gameObject, ItemComponentTrigger.Type.LeftHand, OnComponentEnterTrigger, OnComponentExitTrigger, OnComponentAttachItemTrigger);
			InitComponentTrigger(model.Find("Body/RightHand/UpperArm/LowerArm").gameObject, ItemComponentTrigger.Type.RightHand, OnComponentEnterTrigger, OnComponentExitTrigger, OnComponentAttachItemTrigger);
			InitComponentTrigger(leftLeg.transform.gameObject, ItemComponentTrigger.Type.LeftLeg, OnComponentEnterTrigger, OnComponentExitTrigger, OnComponentAttachItemTrigger);
			InitComponentTrigger(rightLeg.transform.gameObject, ItemComponentTrigger.Type.RightLeg, OnComponentEnterTrigger, OnComponentExitTrigger, OnComponentAttachItemTrigger);
			InitComponentTrigger(head.transform.gameObject, ItemComponentTrigger.Type.Head, null, null, OnComponentAttachItemTrigger);
			InitComponentTrigger(face.transform.gameObject, ItemComponentTrigger.Type.Face, null, null, OnComponentAttachItemTrigger);
			InitComponentTrigger(face.mouth.gameObject, ItemComponentTrigger.Type.Mouth, OnComponentEnterTrigger, OnComponentExitTrigger, null);
			InitComponentTrigger(body.transform.gameObject, ItemComponentTrigger.Type.Body, null, null, OnComponentAttachItemTrigger);
			animator = new CharacterAnimator(leftHand, rightHand, leftLeg, rightLeg);
			InitTops(archiveData.topsId);
			InitTopsIcon(archiveData.topsIconId);
			InitPants(archiveData.pantsId);
			InitShoes(archiveData.shoesId);
			InitBody(archiveData.bodyId, archiveData.bodyColor);
			InitHead(archiveData.headId);
			InitHair(archiveData.hairId, archiveData.hairColor);
			InitFace(archiveData.browId, archiveData.eyeId, archiveData.noseId, archiveData.mouthId, archiveData.featureId);
			ResetBlinkTime();
		}

		public override void ResetState()
		{
			base.ResetState();
			ResetPosition();
		}

		protected virtual void ResetPosition()
		{
			if (archiveData.mapId == Singleton<Scene>.Instance.GetMapId() && (attachType != AttachType.Sit || !(parentItem != null) || (parentItem.itemData.sitType != 1 && parentItem.itemData.sitType != 3)))
			{
				SetPosition(archiveData.mapX, archiveData.mapY);
				SetArchiveDataPosition(base.transform.position);
			}
		}

		public virtual void CalculateHeight()
		{
			float num = 2.9f;
			float num2 = 0f;
			if (frontHair != null && frontHair.IsVisibled())
			{
				num2 = ((!(frontHair.hairHeight >= backHair.hairHeight)) ? (hairStartY + backHair.hairHeight) : (hairStartY + frontHair.hairHeight));
				if (num2 > num)
				{
					num = num2;
				}
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i].attachType == AttachType.PutHead || childItems[i].attachType == AttachType.PutFace)
				{
					num2 = headStartY + childItems[i].transform.localPosition.y + childItems[i].model.localPosition.y * 2f;
					if (num2 > num)
					{
						num = num2;
					}
				}
			}
			characterHeight = num;
		}

		public void SetHalfSideToBack(bool toBack, bool isLeft)
		{
			if (toBack)
			{
				if (isLeft)
				{
					if (leftHand != null)
					{
						leftHand.transform.SetLocalZ(0.0001f);
					}
					if (leftLeg != null)
					{
						leftLeg.transform.SetLocalZ(0.0001f);
					}
					if (rightHand != null)
					{
						rightHand.transform.SetLocalZ(0f);
					}
					if (rightLeg != null)
					{
						rightLeg.transform.SetLocalZ(0f);
					}
				}
				else
				{
					if (leftHand != null)
					{
						leftHand.transform.SetLocalZ(0f);
					}
					if (leftLeg != null)
					{
						leftLeg.transform.SetLocalZ(0f);
					}
					if (rightHand != null)
					{
						rightHand.transform.SetLocalZ(0.0001f);
					}
					if (rightLeg != null)
					{
						rightLeg.transform.SetLocalZ(0.0001f);
					}
				}
			}
			else
			{
				if (leftHand != null)
				{
					leftHand.transform.SetLocalZ(0f);
				}
				if (leftLeg != null)
				{
					leftLeg.transform.SetLocalZ(0f);
				}
				if (rightHand != null)
				{
					rightHand.transform.SetLocalZ(0f);
				}
				if (rightLeg != null)
				{
					rightLeg.transform.SetLocalZ(0f);
				}
			}
		}

		public int GetTopsId()
		{
			if (body != null)
			{
				return body.topsId;
			}
			return 0;
		}

		public bool ChangeTops(ClothingItem tops)
		{
			if (isLock)
			{
				return false;
			}
			bool flag = false;
			for (int i = 0; i < childItems.Count; i++)
			{
				BaseItem baseItem = childItems[i];
				if (baseItem.attachType == AttachType.Wear && baseItem.itemData.scriptType == 14)
				{
					baseItem.SetPosition(base.transform.position.x, base.transform.position.y + 0.852f);
					ReleaseAttachItem(baseItem);
					((ClothingItem)baseItem).CheckState();
					baseItem.DropDown(base.transform.position + new Vector3(0f, -0.48f, 0f));
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				ItemData clothingDataByTopsId = Singleton<SceneModel>.Instance.GetClothingDataByTopsId(body.topsId);
				if (clothingDataByTopsId != null)
				{
					BaseItem baseItem2 = Singleton<Scene>.Instance.CreateItem(clothingDataByTopsId.id, base.transform.position + new Vector3(0f, 0.852f), 0);
					((ClothingItem)baseItem2).SetIcon(body.topsIconId);
					baseItem2.DropDown(base.transform.position + new Vector3(0f, -0.48f, 0f));
				}
			}
			if (tops.itemData.topsId == 75 || tops.itemData.topsId == 76)
			{
				ChangePants(0);
				ChangeShoes(0);
			}
			InitTops(tops.itemData.topsId);
			InitTopsIcon(tops.topsIconId);
			AttachItem(tops, DepthType.Front, AttachType.Wear, false);
			Singleton<AudioManager>.Instance.PlaySound("sound_explode");
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", base.transform.position + new Vector3(0f, 1.2f, -0.003f), 1f);
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 1f, -0.003f), 3f);
			return true;
		}

		public void IsLock(bool val)
		{
			isLock = val;
			SetColliderEnabled(!val);
		}

		public virtual void InitTops(int id)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			body.SetTops(id, transform.Find("Model/Body/Tops/" + id), transform.Find("Model/Body/Tops/" + id + "Back"));
			leftHand.SetClothing(id, transform.Find("Model/Body/LeftHand/UpperArm/Clothing/" + id), transform.Find("Model/Body/LeftHand/UpperArm/LowerArm/Clothing/" + id));
			rightHand.SetClothing(id, transform.Find("Model/Body/RightHand/UpperArm/Clothing/" + id), transform.Find("Model/Body/RightHand/UpperArm/LowerArm/Clothing/" + id));
		}

		public void InitTopsIcon(int id)
		{
			body.SetTopsIcon(id);
		}

		public void ChangeHeadColor(Color32 color)
		{
			if (!headColor.Equals(color))
			{
				headColor = color;
				InitHeadColor();
			}
		}

		public void InitHeadColor()
		{
			if (head != null)
			{
				if (headColor.r == 0 && headColor.g == 0 && headColor.b == 0)
				{
					head.SetColor(body.bodyColor);
				}
				else
				{
					head.SetColor(headColor);
				}
			}
		}

		public bool ChangePants(int id)
		{
			if (isLock)
			{
				return false;
			}
			ItemData itemDataByPantsId = Singleton<SceneModel>.Instance.GetItemDataByPantsId(body.pantsId);
			if (itemDataByPantsId != null)
			{
				BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(itemDataByPantsId.id, base.transform.position + new Vector3(0f, 0.852f), 0);
				baseItem.DropDown(base.transform.position + new Vector3(0f, -0.4f, 0f));
			}
			if (id == 34 || id == 35)
			{
				ChangeShoes(0);
			}
			InitPants(id);
			Singleton<AudioManager>.Instance.PlaySound("sound_explode");
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", base.transform.position + new Vector3(0f, 0.4f, -0.003f), 1f);
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 0.4f, -0.003f), 3f);
			return true;
		}

		public void InitPants(int id)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			body.SetPants(id, transform.Find("Model/Body/Pants/" + id));
			leftLeg.SetClothing(id, transform.Find("Model/Body/LeftLeg/UpperLeg/Clothing/" + id), transform.Find("Model/Body/LeftLeg/UpperLeg/LowerLeg/Clothing/" + id));
			rightLeg.SetClothing(id, transform.Find("Model/Body/RightLeg/UpperLeg/Clothing/" + id), transform.Find("Model/Body/RightLeg/UpperLeg/LowerLeg/Clothing/" + id));
		}

		public bool ChangeShoes(int id)
		{
			if (isLock)
			{
				return false;
			}
			ItemData itemDataByShoesId = Singleton<SceneModel>.Instance.GetItemDataByShoesId(leftLeg.shoesId);
			if (itemDataByShoesId != null)
			{
				BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(itemDataByShoesId.id, base.transform.position, 0);
				baseItem.DropDown(base.transform.position + new Vector3(0f, -0.5f, 0f));
			}
			InitShoes(id);
			Singleton<AudioManager>.Instance.PlaySound("sound_explode");
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_explode_1", base.transform.position + new Vector3(0f, 0.6f, -0.003f), 1f);
			Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 0.2f, -0.003f), 3f);
			return true;
		}

		public void InitShoes(int id)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			leftLeg.SetShoes(id, transform.Find("Model/Body/LeftLeg/UpperLeg/LowerLeg/Shoe/" + id));
			rightLeg.SetShoes(id, transform.Find("Model/Body/RightLeg/UpperLeg/LowerLeg/Shoe/" + id));
		}

		public void InitHair(int id, Color32 color)
		{
			SetHair(id);
			SetHairColor(color);
		}

		public void SetHair(int id)
		{
			if (frontHair != null)
			{
				Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
				frontHair.SetHair(id, transform.Find("Model/Body/Head/FrontHair/" + id));
				backHair.SetHair(id, transform.Find("Model/Body/Head/BackHair/" + id));
				CalculateHeight();
			}
		}

		public int GetHairId()
		{
			if (frontHair != null)
			{
				return frontHair.hairId;
			}
			return 0;
		}

		public void SetHairColor(Color32 color)
		{
			if (frontHair != null)
			{
				frontHair.SetHairColor(color);
				backHair.SetHairColor(color);
			}
		}

		public Color32 GetHairColor()
		{
			if (frontHair != null)
			{
				return frontHair.color;
			}
			return Color.black;
		}

		public void InitHead(int id)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			head.SetHead(id, transform.Find("Model/Body/Head/" + id));
			InitHeadColor();
		}

		public virtual void InitBody(int id, Color32 color)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			body.SetBody(id, transform.Find("Model/Body/" + id), color);
			if (leftHand != null)
			{
				leftHand.SetBody(id, transform.Find("Model/Body/LeftHand/UpperArm/" + id), transform.Find("Model/Body/LeftHand/UpperArm/LowerArm/" + id), color);
				rightHand.SetBody(id, transform.Find("Model/Body/RightHand/UpperArm/" + id), transform.Find("Model/Body/RightHand/UpperArm/LowerArm/" + id), color);
				leftLeg.SetBody(id, transform.Find("Model/Body/LeftLeg/UpperLeg/" + id), transform.Find("Model/Body/LeftLeg/UpperLeg/LowerLeg/" + id), color);
				rightLeg.SetBody(id, transform.Find("Model/Body/RightLeg/UpperLeg/" + id), transform.Find("Model/Body/RightLeg/UpperLeg/LowerLeg/" + id), color);
			}
		}

		public void SetBodyColor(Color32 color)
		{
			body.SetColor(color);
			InitHeadColor();
			leftHand.SetColor(color);
			rightHand.SetColor(color);
			leftLeg.SetColor(color);
			rightLeg.SetColor(color);
		}

		public void InitFace(int browId, int eyeId, int noseId, int mouthId, int featureId)
		{
			Transform transform = Singleton<AssetBundleManager>.Instance.characterResource.transform;
			face.SetBrow(browId, transform.Find("Model/Body/Head/Face/Brow/" + browId));
			face.SetEye(eyeId, transform.Find("Model/Body/Head/Face/Eye/" + eyeId));
			face.SetNose(noseId, transform.Find("Model/Body/Head/Face/Nose/" + noseId));
			face.SetMouth(mouthId, transform.Find("Model/Body/Head/Face/Mouth/" + mouthId));
			face.SetFeature(featureId, transform.Find("Model/Body/Head/Face/Feature/" + featureId));
		}

		public int GetBrowId()
		{
			return face.browId;
		}

		public int GetEyeId()
		{
			return face.eyeId;
		}

		public int GetNoseId()
		{
			return face.noseId;
		}

		public int GetMouthId()
		{
			return face.mouthId;
		}

		public int GetFeatureId()
		{
			return face.featureId;
		}

		public override Color32 GetBodyColor()
		{
			return body.bodyColor;
		}

		protected override void SetComponentTriggerEnabled(bool val)
		{
			base.SetComponentTriggerEnabled(val);
			if (leftLeg != null)
			{
				leftLeg.SetTrigerEnabled(val);
			}
			if (rightLeg != null)
			{
				rightLeg.SetTrigerEnabled(val);
			}
		}

		public void PlayBlowHairAnim()
		{
			isPlayBlowHairAnim = true;
		}

		public void StopBlowHairAnim()
		{
			isPlayBlowHairAnim = false;
			if (frontHair != null)
			{
				frontHair.transform.localScale = frontHair.originalScale;
				frontHair.transform.localEulerAngles = Vector3.zero;
			}
			if (backHair != null)
			{
				backHair.transform.localScale = backHair.originalScale;
				backHair.transform.localEulerAngles = Vector3.zero;
			}
		}

		public void PlayShakeAnim()
		{
			isPlayShakeAnim = true;
		}

		public void StopShakeAnim()
		{
			isPlayShakeAnim = false;
			model.localPosition = new Vector3(curModelOffsetX, curModelOffsetY);
		}

		public bool CanEatThings()
		{
			if (isLock)
			{
				return false;
			}
			if (face != null && face.state == Face.State.Sleep)
			{
				return false;
			}
			return true;
		}

		private bool CanAttachThings()
		{
			if (isLock)
			{
				return false;
			}
			if (face != null && face.state == Face.State.Sleep)
			{
				return false;
			}
			return true;
		}

		public override bool CanPutHead()
		{
			if (isLock)
			{
				return false;
			}
			if (face != null && face.state == Face.State.Sleep)
			{
				return false;
			}
			return true;
		}

		public override bool CanPutFace()
		{
			if (isLock)
			{
				return false;
			}
			if (face != null && face.state == Face.State.Sleep)
			{
				return false;
			}
			return true;
		}

		public override bool CanPutBody()
		{
			if (isLock)
			{
				return false;
			}
			if (face != null && face.state == Face.State.Sleep)
			{
				return false;
			}
			return true;
		}

		public override bool CanPutHand()
		{
			if (isLock)
			{
				return false;
			}
			return true;
		}

		protected override void CheckColls()
		{
			if (base.itemData.scriptType == 1)
			{
				if (storageBoxColls.Count > 0)
				{
					Singleton<Scene>.Instance.AttachItemToLayer(this, 9);
					CheckDontPutOtherSceneItem();
					return;
				}
				if (leftLeg != null && leftLeg.targetList.Count > 0 && leftLeg.targetList[0] != null && leftLeg.targetList[0].CanSit() && leftLeg.targetList[0].AttachItem(this, DepthType.Front, AttachType.Sit, false))
				{
					if (leftLeg.targetList[0].itemData.sitType == 1)
					{
						FreeFall(base.transform.position, leftLeg.targetList[0].GetSitPoint().position - new Vector3(0f, 0.852f));
						return;
					}
					if (leftLeg.targetList[0].itemData.sitType == 3)
					{
						SetArchiveDataPosition(leftLeg.targetList[0].GetSitPoint().position - new Vector3(0f, 0.852f));
						MoveToLocalPosition(new Vector3(0f, -0.852f));
						return;
					}
					PlacePointData placePointData = CheckPlatform(base.transform.position + new Vector3(0f, 0.852f), 10, leftLeg.targetList[0].GetPlatform());
					if (placePointData.result)
					{
						FreeFall(base.transform.position, placePointData.position - new Vector2(0f, 0.852f));
					}
					else
					{
						FreeFall(base.transform.position, leftLeg.targetList[0].model.position - new Vector3(0f, 0.852f));
					}
					return;
				}
				for (int i = 0; i < platformColls.Count; i++)
				{
					ColliderData colliderData = platformColls[i];
					if (!(colliderData.coll.transform.position.y <= base.transform.position.y) || !colliderData.item.CanLie())
					{
						continue;
					}
					if (colliderData.item.itemData.lieType == 1)
					{
						if (colliderData.item.AttachItem(this, DepthType.Ahead, AttachType.LieLeft, false))
						{
							FreeFall(base.transform.position, colliderData.item.GetLiePoint().position);
							return;
						}
					}
					else if (colliderData.item.itemData.lieType == 2)
					{
						if (colliderData.item.AttachItem(this, DepthType.Ahead, AttachType.LieRight, false))
						{
							FreeFall(base.transform.position, colliderData.item.GetLiePoint().position);
							return;
						}
					}
					else if (colliderData.item.itemData.lieType == 3 && colliderData.item.AttachItem(this, DepthType.Ahead, AttachType.LieCenter, false))
					{
						FreeFall(base.transform.position, colliderData.item.GetLiePoint().position);
						return;
					}
				}
			}
			base.CheckColls();
		}

		public void ChangeAnimation(CharacterAnimator.AnimName animName)
		{
			animator.ChangeAnimation(animName);
		}

		protected override void ResetComponentState()
		{
			ChangeAnimation(CharacterAnimator.AnimName.Idle);
		}

		protected void InitComponentTrigger(GameObject obj, ItemComponentTrigger.Type type, ItemComponentTrigger.EnterCollision onEnter, ItemComponentTrigger.ExitCollision onExit, ItemComponentTrigger.AttachItem onAttachItem)
		{
			obj.layer = 12;
			ItemComponentTrigger itemComponentTrigger = obj.AddComponent<ItemComponentTrigger>();
			itemComponentTrigger.Init(this, type, onEnter, onExit, onAttachItem);
		}

		public void OnComponentEnterTrigger(BaseItem item, ItemComponentTrigger trigger)
		{
			if (parentItem == item || isLock)
			{
				return;
			}
			if (trigger.type == ItemComponentTrigger.Type.LeftHand)
			{
				if (item.itemData.canHold && leftHand.targetItem == null && leftHand.takeItem == null && face.state != Face.State.Sleep)
				{
					leftHand.targetItem = item;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.RightHand)
			{
				if (item.itemData.canHold && rightHand.targetItem == null && rightHand.takeItem == null && face.state != Face.State.Sleep)
				{
					rightHand.targetItem = item;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.Mouth)
			{
				if (item.CanEat() && CanEatThings())
				{
					ChangeFaceAnimation(Face.State.Default);
					SetMouthState(Face.MouthState.Open);
				}
			}
			else if (isDrag && !isInSBArea && (trigger.type == ItemComponentTrigger.Type.LeftLeg || trigger.type == ItemComponentTrigger.Type.RightLeg) && item.CanSit())
			{
				leftLeg.AddTargetItem(item);
				rightLeg.AddTargetItem(item);
			}
		}

		public void OnComponentExitTrigger(BaseItem item, ItemComponentTrigger trigger)
		{
			if (trigger.type == ItemComponentTrigger.Type.LeftHand)
			{
				if (leftHand.targetItem == item)
				{
					leftHand.targetItem = null;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.RightHand)
			{
				if (rightHand.targetItem == item)
				{
					rightHand.targetItem = null;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.Mouth)
			{
				if (item.CanEat() && CanEatThings())
				{
					SetMouthState(Face.MouthState.Normal);
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.LeftLeg || trigger.type == ItemComponentTrigger.Type.RightLeg)
			{
				leftLeg.RemoveTargetItem(item);
				rightLeg.RemoveTargetItem(item);
			}
		}

		public Transform OnComponentAttachItemTrigger(BaseItem item, ItemComponentTrigger trigger)
		{
			if (!CanAttachThings())
			{
				return null;
			}
			if (trigger.type == ItemComponentTrigger.Type.LeftHand)
			{
				if (leftHand != null)
				{
					if (item.itemData.canPutHand)
					{
						if (AttachItem(item, DepthType.Front, AttachType.PutLeftHand, false))
						{
							return leftHand.lowerArm;
						}
					}
					else if (leftHand.takeItem == null && AttachItem(item, DepthType.Front, AttachType.LeftHandTake, false))
					{
						return leftHand.takePoint;
					}
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.RightHand)
			{
				if (rightHand != null)
				{
					if (item.itemData.canPutHand)
					{
						if (AttachItem(item, DepthType.Front, AttachType.PutRightHand, false))
						{
							return rightHand.lowerArm;
						}
					}
					else if (rightHand.takeItem == null && AttachItem(item, DepthType.Front, AttachType.RightHandTake, false))
					{
						return rightHand.takePoint;
					}
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.LeftLeg)
			{
				if (AttachItem(item, DepthType.Ahead, AttachType.PutLeftLeg, false))
				{
					return leftLeg.lowerLeg;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.RightLeg)
			{
				if (AttachItem(item, DepthType.Ahead, AttachType.PutRightLeg, false))
				{
					return rightLeg.lowerLeg;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.Head)
			{
				if (AttachItem(item, DepthType.Front, AttachType.PutHead, false))
				{
					return head.transform;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.Face)
			{
				if (AttachItem(item, DepthType.Front, AttachType.PutFace, false))
				{
					return head.transform;
				}
			}
			else if (trigger.type == ItemComponentTrigger.Type.Body && AttachItem(item, DepthType.Front, AttachType.PutBody, false))
			{
				return body.transform;
			}
			return null;
		}

		public override bool AttachItem(BaseItem item, DepthType depthType, AttachType attachType, bool updatePosition)
		{
			if (item.parentItem != null)
			{
				return false;
			}
			if (archiveData.layer == 9 && item.itemData.dontPutOtherScene)
			{
				return false;
			}
			switch (attachType)
			{
			case AttachType.LeftHandTake:
				if (!updatePosition && leftHand.state != 0)
				{
					return false;
				}
				AttachItemToHandTake(leftHand, item, updatePosition);
				break;
			case AttachType.RightHandTake:
				if (!updatePosition && rightHand.state != 0)
				{
					return false;
				}
				AttachItemToHandTake(rightHand, item, updatePosition);
				break;
			case AttachType.PutHead:
				AttachItemToHead(item, updatePosition);
				break;
			case AttachType.PutFace:
				AttachItemToFace(item, updatePosition);
				break;
			case AttachType.PutBody:
				AttachItemToBody(item, updatePosition);
				break;
			case AttachType.Wear:
				item.SetParent(body.transform);
				break;
			case AttachType.PutLeftHand:
				AttachItemToHand(leftHand, item, updatePosition);
				break;
			case AttachType.PutRightHand:
				AttachItemToHand(rightHand, item, updatePosition);
				break;
			case AttachType.PutLeftLeg:
				AttachItemToLeg(leftLeg, item, updatePosition);
				break;
			case AttachType.PutRightLeg:
				AttachItemToLeg(rightLeg, item, updatePosition);
				break;
			}
			bool flag = base.AttachItem(item, depthType, attachType, updatePosition);
			switch (attachType)
			{
			case AttachType.PutHead:
			case AttachType.PutFace:
				CalculateHeight();
				break;
			case AttachType.PutLeftHand:
				if (flag && updatePosition)
				{
					item.ResetLocalScale();
				}
				break;
			}
			return flag;
		}

		private void AttachItemToHead(BaseItem item, bool updatePosition)
		{
			item.SetParent(head.transform);
			item.SetLocalRotation(new Vector3(0f, 0f, item.itemData.putHeadAngle));
			if (item.itemData.hideHair)
			{
				if (frontHair != null)
				{
					frontHair.SetHairVisible(false);
				}
				if (backHair != null)
				{
					backHair.SetHairVisible(false);
				}
			}
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.putHeadX, item.itemData.putHeadY);
				item.SetLocalScale(Vector3.one);
			}
		}

		private void AttachItemToFace(BaseItem item, bool updatePosition)
		{
			item.SetParent(head.transform);
			item.SetLocalRotation(new Vector3(0f, 0f, item.itemData.putFaceAngle));
			if (item.itemData.hideHair)
			{
				if (frontHair != null)
				{
					frontHair.SetHairVisible(false);
				}
				if (backHair != null)
				{
					backHair.SetHairVisible(false);
				}
			}
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.putFaceX, item.itemData.putFaceY);
				item.SetLocalScale(Vector3.one);
			}
		}

		private void AttachItemToBody(BaseItem item, bool updatePosition)
		{
			item.SetParent(body.transform);
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.putBodyX, item.itemData.putBodyY);
			}
		}

		private void AttachItemToHand(Hand hand, BaseItem item, bool updatePosition)
		{
			item.SetParent(hand.lowerArm);
			if (item.itemData.hideTops)
			{
				hand.SetLowerArmClothingVisible(false);
			}
			if (item.itemData.putHandFlip && hand.dir == Hand.Dir.Left)
			{
				item.FlipHorizontal(false);
			}
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.putHandX, item.itemData.putHandY);
			}
		}

		private void AttachItemToLeg(Leg leg, BaseItem item, bool updatePosition)
		{
			item.SetParent(leg.lowerLeg);
			item.SetLocalRotation(new Vector3(0f, 0f, item.itemData.putLegAngle));
			if (item.itemData.hidePants)
			{
				leg.SetLowerLegClothingVisible(false);
			}
			if (item.itemData.hideShoes)
			{
				leg.SetShoesVisible(false);
			}
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.putLegX, item.itemData.putLegY);
			}
		}

		private void AttachItemToHandTake(Hand hand, BaseItem item, bool updatePosition)
		{
			hand.SetTakeItem(item);
			item.SetParent(hand.takePoint);
			if (item.itemData.holdFlip && hand.dir == Hand.Dir.Left)
			{
				item.FlipHorizontal(false);
			}
			item.SetLocalRotation(new Vector3(0f, 0f, item.itemData.holdAngle));
			if (updatePosition)
			{
				item.SetLocalPosition(item.itemData.holdX, item.itemData.holdY);
			}
		}

		public override void ReleaseAttachItem(BaseItem item)
		{
			bool flag = false;
			if (item.attachType == AttachType.LeftHandTake)
			{
				ReleaseAttachItemFromHandTake(leftHand, item);
			}
			else if (item.attachType == AttachType.RightHandTake)
			{
				ReleaseAttachItemFromHandTake(rightHand, item);
			}
			else if (item.attachType == AttachType.PutLeftHand)
			{
				ReleaseAttachItemFromHand(leftHand, item);
			}
			else if (item.attachType == AttachType.PutRightHand)
			{
				ReleaseAttachItemFromHand(rightHand, item);
			}
			else if (item.attachType == AttachType.PutLeftLeg)
			{
				ReleaseAttachItemFromLeg(leftLeg, item);
			}
			else if (item.attachType == AttachType.PutRightLeg)
			{
				ReleaseAttachItemFromLeg(rightLeg, item);
			}
			else if (item.attachType == AttachType.PutHead)
			{
				ReleaseAttachItemFromHead(item);
				flag = true;
			}
			else if (item.attachType == AttachType.PutFace)
			{
				ReleaseAttachItemFromFace(item);
				flag = true;
			}
			base.ReleaseAttachItem(item);
			if (flag)
			{
				CalculateHeight();
			}
		}

		private void ReleaseAttachItemFromHandTake(Hand hand, BaseItem item)
		{
			if (hand.takeItem == item)
			{
				float z = item.GetRotation().z;
				Singleton<Scene>.Instance.AttachItemToLayer(item, 0);
				hand.SetTakeItem(null);
				item.SetRotation(new Vector3(0f, 0f, z));
				if (item.itemData.holdFlip && hand.dir == Hand.Dir.Left)
				{
					item.FlipHorizontal(true);
				}
			}
		}

		private void ReleaseAttachItemFromHand(Hand hand, BaseItem item)
		{
			if (item.itemData.hideTops)
			{
				for (int i = 0; i < childItems.Count; i++)
				{
					BaseItem baseItem = childItems[i];
					if (baseItem == item)
					{
						continue;
					}
					if (hand.dir == Hand.Dir.Left)
					{
						if (baseItem.itemData.hideTops && baseItem.attachType == AttachType.PutLeftHand)
						{
							hand.SetLowerArmClothingVisible(false);
							return;
						}
					}
					else if (hand.dir == Hand.Dir.Right && baseItem.itemData.hideTops && baseItem.attachType == AttachType.PutRightHand)
					{
						hand.SetLowerArmClothingVisible(false);
						return;
					}
				}
				hand.SetLowerArmClothingVisible(true);
			}
			if (item.itemData.putHandFlip && hand.dir == Hand.Dir.Left)
			{
				item.FlipHorizontal(true);
			}
		}

		private void ReleaseAttachItemFromLeg(Leg leg, BaseItem item)
		{
			if (item.itemData.hidePants)
			{
				for (int i = 0; i < childItems.Count; i++)
				{
					BaseItem baseItem = childItems[i];
					if (baseItem == item)
					{
						continue;
					}
					if (leg.dir == Leg.Dir.Left)
					{
						if (baseItem.itemData.hidePants && baseItem.attachType == AttachType.PutLeftLeg)
						{
							leg.SetLowerLegClothingVisible(false);
							return;
						}
					}
					else if (leg.dir == Leg.Dir.Right && baseItem.itemData.hidePants && baseItem.attachType == AttachType.PutRightLeg)
					{
						leg.SetLowerLegClothingVisible(false);
						return;
					}
				}
				leg.SetLowerLegClothingVisible(true);
			}
			if (!item.itemData.hideShoes)
			{
				return;
			}
			for (int j = 0; j < childItems.Count; j++)
			{
				BaseItem baseItem2 = childItems[j];
				if (baseItem2 == item)
				{
					continue;
				}
				if (leg.dir == Leg.Dir.Left)
				{
					if (baseItem2.itemData.hideShoes && baseItem2.attachType == AttachType.PutLeftLeg)
					{
						leg.SetShoesVisible(false);
						return;
					}
				}
				else if (leg.dir == Leg.Dir.Right && baseItem2.itemData.hideShoes && baseItem2.attachType == AttachType.PutRightLeg)
				{
					leg.SetShoesVisible(false);
					return;
				}
			}
			leg.SetShoesVisible(true);
		}

		private void ReleaseAttachItemFromHead(BaseItem item)
		{
			if (!item.itemData.hideHair)
			{
				return;
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i] != item && (childItems[i].attachType == AttachType.PutHead || childItems[i].attachType == AttachType.PutFace) && childItems[i].itemData.hideHair)
				{
					return;
				}
			}
			if (frontHair != null)
			{
				frontHair.SetHairVisible(true);
			}
			if (backHair != null)
			{
				backHair.SetHairVisible(true);
			}
		}

		private void ReleaseAttachItemFromFace(BaseItem item)
		{
			if (!item.itemData.hideHair)
			{
				return;
			}
			for (int i = 0; i < childItems.Count; i++)
			{
				if (childItems[i] != item && (childItems[i].attachType == AttachType.PutHead || childItems[i].attachType == AttachType.PutFace) && childItems[i].itemData.hideHair)
				{
					return;
				}
			}
			if (frontHair != null)
			{
				frontHair.SetHairVisible(true);
			}
			if (backHair != null)
			{
				backHair.SetHairVisible(true);
			}
		}

		public override bool CanPlacePlatform()
		{
			return true;
		}

		public override void OnReleaseAttachItem(BaseItem oldParent)
		{
			base.OnReleaseAttachItem(oldParent);
			ChangeFaceAnimation(Face.State.Default);
		}

		protected override int CalculateAngle()
		{
			if (attachType == AttachType.LieLeft)
			{
				return 90;
			}
			if (attachType == AttachType.LieRight)
			{
				return -90;
			}
			return base.CalculateAngle();
		}

		public void EatThings(BaseItem eatItem)
		{
			if (!(eatItem == null))
			{
				if (eatItem.itemData.isPoison)
				{
					waitCure = 0f;
					IsIll(true);
				}
				else if (eatItem.itemData.type == 10)
				{
					Cure();
				}
				ChangeFaceAnimation(Face.State.Eat);
				Singleton<AudioManager>.Instance.PlaySound("sound_eat");
				if (parentItem != null)
				{
					parentItem.OnChildDoThing(this, ChildDoThingType.Eat, eatItem);
				}
			}
		}

		public void Cure()
		{
			if (isIll || ((headColor.r != 0 || headColor.g != 0) && headColor.b != 0))
			{
				waitCure = 1f;
			}
		}

		public void IsIll(bool val)
		{
			if (isIll != val)
			{
				isIll = val;
				if (face != null)
				{
					face.IsIll(isIll);
				}
			}
		}

		public void ChangeFaceAnimation(Face.State anim)
		{
			if (face != null)
			{
				face.ChangeAnimation(anim);
			}
		}

		public void SetMouthState(Face.MouthState state)
		{
			if (face != null)
			{
				face.ChangeMouthState(state);
			}
		}

		public void SetBrowState()
		{
		}

		public override void SetColliderEnabled(bool val)
		{
			base.SetColliderEnabled(val);
			if (body != null)
			{
                body.SetBoxColliderEnabled(val);
			}
			if (head != null)
			{
				head.SetBoxColliderEnabled(val);
			}
			if (face != null)
			{
				face.SetBoxColliderEnabled(val);
			}
			if (leftHand != null)
			{
				leftHand.SetBoxColliderEnabled(val);
			}
			if (rightHand != null)
			{
				rightHand.SetBoxColliderEnabled(val);
			}
			if (leftLeg != null)
			{
				leftLeg.SetBoxColliderEnabled(val);
			}
			if (rightLeg != null)
			{
				rightLeg.SetBoxColliderEnabled(val);
			}
		}

		public bool CanUseBandage(ItemComponentTrigger trigger)
		{
			if (trigger == null)
			{
				return false;
			}
			if (trigger.type == ItemComponentTrigger.Type.LeftHand)
			{
				return !ChildContainsBandage(AttachType.PutLeftHand);
			}
			if (trigger.type == ItemComponentTrigger.Type.RightHand)
			{
				return !ChildContainsBandage(AttachType.PutRightHand);
			}
			if (trigger.type == ItemComponentTrigger.Type.LeftLeg)
			{
				return !ChildContainsBandage(AttachType.PutLeftLeg);
			}
			if (trigger.type == ItemComponentTrigger.Type.RightLeg)
			{
				return !ChildContainsBandage(AttachType.PutRightLeg);
			}
			if (trigger.type == ItemComponentTrigger.Type.Face || trigger.type == ItemComponentTrigger.Type.Head)
			{
				return !ChildContainsBandage(AttachType.PutFace) && !ChildContainsBandage(AttachType.PutHead);
			}
			return false;
		}

		private bool ChildContainsBandage(AttachType attachType)
		{
			for (int i = 0; i < childItems.Count; i++)
			{
				BaseItem baseItem = childItems[i];
				if (baseItem != null && baseItem.itemData.scriptType == 122 && baseItem.attachType == attachType)
				{
					return true;
				}
			}
			return false;
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			LateUpdateAction();
		}

		protected virtual void LateUpdateAction()
		{
			LateUpdateHairAnim();
			LateUpdateShakeAnim();
			LateUpdateBlink();
			LateUpdateCure();
			face.LatedUpdate();
			leftHand.LateUpdate();
			rightHand.LateUpdate();
			leftLeg.LateUpdate();
			rightLeg.LateUpdate();
		}

		private void LateUpdateHairAnim()
		{
			if (frontHair != null && isPlayBlowHairAnim)
			{
				tempHairScale = Random.Range(0.98f, 1.02f);
				frontHair.transform.localScale = frontHair.originalScale * tempHairScale;
				backHair.transform.localScale = backHair.originalScale * tempHairScale;
				tempHairAngle = Random.Range(-2f, 2f);
				frontHair.transform.localEulerAngles = new Vector3(0f, 0f, tempHairAngle);
				backHair.transform.localEulerAngles = new Vector3(0f, 0f, tempHairAngle);
			}
		}

		private void LateUpdateShakeAnim()
		{
			if (isPlayShakeAnim)
			{
				tempShakeX = Random.Range(-0.03f, 0.03f);
				tempShakeY = Random.Range(-0.04f, 0.04f);
				model.localPosition = new Vector3(curModelOffsetX + tempShakeX, curModelOffsetY + tempShakeY);
			}
		}

		protected void LateUpdateBlink()
		{
			blinkTime -= Time.deltaTime;
			if (blinkTime <= 0f)
			{
				ResetBlinkTime();
				face.ChangeAnimation(Face.State.Blink);
			}
		}

		protected void LateUpdateCure()
		{
			if (!(waitCure > 0f))
			{
				return;
			}
			waitCure -= Time.deltaTime;
			if (waitCure <= 0f)
			{
				waitCure = 0f;
				IsIll(false);
				ChangeFaceAnimation(Face.State.Happy);
				ChangeHeadColor(new Color32(0, 0, 0, 0));
				Singleton<AudioManager>.Instance.PlaySound("sound_blink");
				if (base.itemData.scriptType == 123)
				{
					Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 0.5f, -0.001f), 3f);
				}
				else
				{
					Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", base.transform.position + new Vector3(0f, 2f, -0.001f), 3f);
				}
			}
		}

		public override void UpdateFrontDepth()
		{
			base.UpdateFrontDepth();
			if (parentItem != null && parentItem.itemData.scriptType == 157)
			{
				base.transform.SetZ(parentItem.transform.position.z);
			}
		}

		protected override void OnMove()
		{
			if (lastMovePos.x != -100f && animator != null)
			{
				float num = lastMovePos.x - base.transform.position.x;
				if (num > 0.2f)
				{
					animator.AddPower(1, num - 0.2f);
				}
				else if (num < -0.2f)
				{
					animator.AddPower(2, 0f - num + 0.2f);
				}
				else
				{
					float num2 = lastMovePos.y - base.transform.position.y;
					if (num2 > 0f)
					{
						animator.AddPower(0, num2);
					}
				}
			}
			lastMovePos = base.transform.position;
		}

		protected virtual void ResetBlinkTime()
		{
			blinkTime = Random.Range(7f, 12f);
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["13"] = head.headId;
			obj["16"] = body.topsId;
			obj["15"] = body.bodyId;
			obj["20"] = face.browId;
			obj["21"] = face.eyeId;
			obj["22"] = face.noseId;
			obj["23"] = face.mouthId;
			obj["55"] = face.featureId;
			obj["27"] = body.bodyColor.r;
			obj["28"] = body.bodyColor.g;
			obj["29"] = body.bodyColor.b;
			obj["59"] = (isIll ? 1 : 0);
			obj["30"] = headColor.r;
			obj["31"] = headColor.g;
			obj["32"] = headColor.b;
			PackDetialData(obj);
		}

		protected virtual void PackDetialData(JSONObject obj)
		{
			obj["14"] = frontHair.hairId;
			obj["17"] = body.topsIconId;
			obj["18"] = body.pantsId;
			obj["19"] = leftLeg.shoesId;
			obj["24"] = frontHair.color.r;
			obj["25"] = frontHair.color.g;
			obj["26"] = frontHair.color.b;
			if (archiveData.mapId != 0)
			{
				if (archiveData.mapId == Singleton<Scene>.Instance.GetMapId())
				{
					obj["64"] = base.transform.position.x.ToString("F5");
					obj["65"] = base.transform.position.y.ToString("F5");
				}
				else
				{
					obj["64"] = archiveData.mapX.ToString("F5");
					obj["65"] = archiveData.mapY.ToString("F5");
				}
			}
		}
	}
}
